package peer.NetworkManager;

import java.net.*;
import java.util.ArrayList;
import java.util.List;

import common.Packet;


public class PacketFactory 
{
	
	//creates a nw_connect packet or its corresponding
	//acknowledgement of response
	public Packet requestConnection(InetAddress serverAddress, boolean isAck)
	{
		Packet requestConnectionPacket = new Packet();
		if(isAck)
			requestConnectionPacket.setType(Packet.Type.nw_connect_aok);
		else
			requestConnectionPacket.setType(Packet.Type.nw_connect);
		
		return requestConnectionPacket;
	}
	
	//creates a packet that requests more peers, or its
	//corresponding acknowledgement of response
	public Packet requestPeerList(InetAddress serverAddress, boolean isAck)
	{
		Packet requestPeerListPacket = new common.Packet();
		if(isAck)
			requestPeerListPacket.setType(Packet.Type.nw_newpeers_aok);
		else
			requestPeerListPacket.setType(Packet.Type.nw_newpeers);
		
		return requestPeerListPacket;	
	}
	
	
	public Packet aliveResponse(InetAddress serverAddress)
	{
		Packet imAlivePacket = new Packet();
		imAlivePacket.setType(Packet.Type.nw_pong);
		
		return imAlivePacket;
	}
	
	public Packet searchRequest(String searchString)
	{
		Packet toAdd = new Packet();
		toAdd.setType(Packet.Type.search);
		return toAdd;
	}
}
